#pragma once

#include <QWidget>
#include <mutex>
#include <qcoreevent.h>
#include <qnamespace.h>
#include <string>
#include <memory>
#include "spdlog/common.h"
#include "spdlog/details/log_msg.h"
#include "spdlog/logger.h"
#include <spdlog/formatter.h>
#include <spdlog/pattern_formatter.h>

#include <QThread>


namespace Ui {
class LogListPanel;
}

class LogListPanel : public QWidget {
    Q_OBJECT

public:
    explicit LogListPanel(QWidget *parent = nullptr);
    ~LogListPanel();

private:
    void _logged_callback(const spdlog::details::log_msg& msg);

    void _log_to_ui(spdlog::level::level_enum level, const std::string& str);

    void _init_pb();

    void customEvent(QEvent* e) override;

private:
    Ui::LogListPanel *ui;

    Qt::HANDLE init_thread_handle_;

    std::shared_ptr<spdlog::pattern_formatter> formatter_;
    mutable std::mutex formatter_mutex_;
};
